package logic

import (
	"2210a/commod/commodrpc/commodrpc"
	"2210a/commod/pkg"
	"context"

	"2210a/commod/commodapi/internal/svc"
	"2210a/commod/commodapi/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewShopUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopUpdateLogic {
	return &ShopUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ShopUpdateLogic) ShopUpdate(req *types.ShopUpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	update, err := l.svcCtx.CommodEpc.ShopUpdate(l.ctx, &commodrpc.ShopUpdateRequest{
		Id:        req.Id,
		UserId:    req.UserId,
		Avatar:    req.Avatar,
		ShopName:  req.ShopName,
		Price:     req.Price,
		Address:   req.Address,
		Quantity:  req.Quantity,
		Introduce: req.Introduce,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: pkg.Trl(err.Error()),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "商品修改成功",
		Data:    update.Id,
	}, nil
}
